﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProShoppingPen {

    public partial class FrmOptions : Form {

        IniFile iniFileOpt = new IniFile(AppDomain.CurrentDomain.BaseDirectory+"config.ini");

        public FrmOptions () {
            InitializeComponent( );
        }

        private void btnCancel_Click ( object sender, EventArgs e ) {
            this.Close( );
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnOk_Click ( object sender, EventArgs e ) {

            if (chkBoxAutoUpdate.Checked)
                iniFileOpt.IniWriteValue("config", "autoUpdate","1");
            else
                iniFileOpt.IniWriteValue("config", "autoUpdate", "0");

            if (chkBoxDefaultBrowser.Checked)
                iniFileOpt.IniWriteValue("config", "defaultBrowser", "1");
            else
                iniFileOpt.IniWriteValue("config", "defaultBrowser", "0");

            if (chkBoxPopHome.Checked)
                iniFileOpt.IniWriteValue("config", "popHome", "1");
            else
                iniFileOpt.IniWriteValue("config", "popHome", "0");

            iniFileOpt.IniWriteValue("config", "penSensitive", lblSensitiveValue.Text);

            this.DialogResult = DialogResult.OK;
            this.Close( );

        }

        private void FrmOptions_Load ( object sender, EventArgs e ) {

            try
            {
                string autoUpdate = iniFileOpt.IniReadValue("config", "autoUpdate");
                if (autoUpdate.Equals("1"))
                    chkBoxAutoUpdate.Checked = true;
                else
                    chkBoxAutoUpdate.Checked = false;

                string defaultBrowser = iniFileOpt.IniReadValue("config", "defaultBrowser");
                if (defaultBrowser.Equals("1"))
                    chkBoxDefaultBrowser.Checked = true;
                else
                    chkBoxDefaultBrowser.Checked = false;

                string popHome = iniFileOpt.IniReadValue("config", "popHome");
                if (popHome.Equals("1"))
                    chkBoxPopHome.Checked = true;
                else
                    chkBoxPopHome.Checked = false;

                string penSensitive = null;
                penSensitive = iniFileOpt.IniReadValue("config", "PenSensitive");
                if (penSensitive != null)
                {
                    hScrollBarSensitive.Value = Int32.Parse(penSensitive);
                    lblSensitiveValue.Text = penSensitive;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("配置文件丢失错误！");
                this.Close( );
            }

        }

        private void hScrollBarSensitive_ValueChanged ( object sender, EventArgs e ) {

            lblSensitiveValue.Text = hScrollBarSensitive.Value.ToString();
        }

    }
}
